cmake_minimum_required(VERSION 3.18)
message("Create bundled lib...")

# Find lib.exe
find_program(lib_tool lib.exe)

# remove @PROJECT_NAME@_full.lib
execute_process(
  COMMAND ${CMAKE_COMMAND} -E rm -f ortools_full.lib
  #COMMAND ${CMAKE_COMMAND} -E false
  COMMAND_ECHO STDOUT
  COMMAND_ERROR_IS_FATAL ANY
  WORKING_DIRECTORY "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@"
)

set(DEPS absl_*.lib zlib*.lib re2.lib *protobuf*.lib)
if (@BUILD_Cbc@)
  set(DEPS ${DEPS} Cbc*.lib)
endif()
if (@BUILD_Cgl@)
  set(DEPS ${DEPS} Cgl.lib)
endif()
if (@BUILD_Clp@)
  set(DEPS ${DEPS} Clp*.lib)
endif()
if (@BUILD_Osi@)
  set(DEPS ${DEPS} Osi*.lib)
endif()
if (@BUILD_CoinUtils@)
  set(DEPS ${DEPS} CoinUtils.lib)
endif()

if (@BUILD_SCIP@)
  set(DEPS ${DEPS} libscip.lib)
endif()
if (@BUILD_GLPK@)
  set(DEPS ${DEPS} libglpk.lib)
endif()

# Bundle all .lib into @PROJECT_NAME@_full.lib
execute_process(
  COMMAND ${lib_tool} /NOLOGO /OUT:@PROJECT_NAME@_full.lib @PROJECT_NAME@.lib ${DEPS}
  #COMMAND ${CMAKE_COMMAND} -E false
  COMMAND_ECHO STDOUT
  COMMAND_ERROR_IS_FATAL ANY
  WORKING_DIRECTORY "@CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@"
)

message("Create bundled lib...DONE")
